﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace WebChatApi.Common
{
    /// <summary>
    /// Enum value for identify different applications.
    /// Enum values are classified in 3 sights: Devices types, products, services.
    /// 
    /// </summary>
    [DataContract]
    public enum ApplicationSource
    {
        /// <summary>
        /// Unknown source as default value.
        /// </summary>
        [EnumMember]
        Unknown = 0,
        #region Device Types(0x0001, 0x0002, ... , 0x000F)
        /// <summary>
        /// The value indicating source is an iOS app.
        /// </summary>
        [EnumMember]
        iOSApp = 0x0001,
        /// <summary>
        /// The value indicating source is an Android app.
        /// </summary>
        [EnumMember]
        AndroidApp = 0x0002,
        /// <summary>
        /// The value indicating source is a Windows Phone app.
        /// </summary>
        [EnumMember]
        WindowsPhoneApp = 0x0003,
        /// <summary>
        /// The value indicating source is a BlackBarry app.
        /// </summary>
        [EnumMember]
        BlackBarry = 0x0004,
        /// <summary>
        /// The value indicating source is Web.
        /// </summary>
        [EnumMember]
        Web = 0x0005,
        /// <summary>
        /// The value indicating source is Service.
        /// </summary>
        [EnumMember]
        Service = 0x0006,
        #endregion
        #region Products (0x0010, 0x0020, ... , 0x0FF0)
        /// <summary>
        /// The value indicating source is Loggers(Health Center) app.
        /// </summary>
        [EnumMember]
        LoggersApp = 0x0010,
        /// <summary>
        /// The value indicating source is Loggers(Health Center) app for iOS.
        /// </summary>
        [EnumMember]
        iOSLoggersApp = LoggersApp | iOSApp,
        /// <summary>
        /// The value indicating source is Patient Manager app.
        /// </summary>
        [EnumMember]
        PatientManagerApp = 0x0020,
        /// <summary>
        /// The value indicating source is Patient Manager app for iOS.
        /// </summary>
        [EnumMember]
        iOSPatientManagerApp = PatientManagerApp | iOSApp,
        /// <summary>
        /// The value indicating source is Jibo app.
        /// </summary>
        [EnumMember]
        JiboApp = 0x0030,
        /// <summary>
        /// The value indicating source is Jibo app for iOS.
        /// </summary>
        [EnumMember]
        iOSJiboApp = JiboApp | iOSApp,
        /// <summary>
        /// The value indicating source is Jibo app for Android.
        /// </summary>
        [EnumMember]
        AndroidJiboApp = JiboApp | AndroidApp,
        #endregion
        #region Services (0x001000, 0x002000, ... , 0xFFF000)
        /// <summary>
        /// The value indicating source is Authority Service.
        /// </summary>
        [EnumMember]
        AuthorityService = 0x001000,
        /// <summary>
        /// The value indicating source is Health Service.
        /// </summary>
        [EnumMember]
        HealthService = 0x002000,
        /// <summary>
        /// The value indicating source is Article Service.
        /// </summary>
        [EnumMember]
        ArticleService = 0x003000,
        /// <summary>
        /// The value indicating source is Drug Service.
        /// </summary>
        [EnumMember]
        DrugService = 0x004000
        #endregion
    }

    /// <summary>
    /// 
    /// </summary>
    public static class ApplicationSourceExtension
    {
        /// <summary>
        /// Gets the platform value.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static int GetPlatformValue(ApplicationSource source)
        {
            return (int)source & 0x000F;
        }

        /// <summary>
        /// Gets the product value.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static int GetProductValue(ApplicationSource source)
        {
            return (int)source & 0x0FF0;
        }

        /// <summary>
        /// Gets the service value.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static int GetServiceValue(ApplicationSource source)
        {
            return (int)source & 0xFFF000;
        }
    }
}
